#include "client.h"
#include <ctype.h>
#include <signal.h>
static int flag = 1;

void ouch(int sig)
{
    flag = 0;
}
int main()
{
    int server_fifo_fd, client_fifo_fd;
    struct data_to_pass_st my_data;
    int read_res;
    int i=0;
    int cs[N]={0},CS[N]={0};

    mkfifo(SERVER_FIFO_NAME, 0777);
    server_fifo_fd = open(SERVER_FIFO_NAME, O_RDONLY);
    if (server_fifo_fd == -1) {
        fprintf(stderr, "Server fifo failure\n");
        exit(EXIT_FAILURE);
    }
   
    struct sigaction act;
    act.sa_handler = ouch;
    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
    sigaction(SIGINT,&act,0);

    while(flag)
    {
        read_res = read(server_fifo_fd, &my_data, sizeof(my_data));
        if (read_res > 0) {


              for(i=0;i<N;i++)
	      {
 		cs[i]+=my_data.cs[i];
	        CS[i]+=my_data.CS[i];
	      }
	      flag = my_data.flag;
        }
    }
    close(server_fifo_fd);
    unlink(SERVER_FIFO_NAME);
    for(i=0;i<N;i++)
       if(cs[i]!=0)
       printf("The total number of %c is %d \n",i+'a',cs[i]); 
    for(i=0;i<N;i++)
       if(CS[i]!=0)
       printf("The total number of %c is %d \n",i+'A',CS[i]);
    exit(EXIT_SUCCESS);
}

